/// 排行榜用户数据模型
/// 包含用户的点赞统计和排名信息
class RankingUserEntity {
  final String userId;
  final int totalLikeCount; // 总收到点赞数
  final int rankPosition; // 排名位置
  final DateTime lastUpdateTime; // 最后更新时间

  const RankingUserEntity({
    required this.userId,
    required this.totalLikeCount,
    required this.rankPosition,
    required this.lastUpdateTime,
  });

  /// 从JSON创建排行榜用户对象
  factory RankingUserEntity.fromJson(Map<String, dynamic> json) {
    return RankingUserEntity(
      userId: json['userId'] as String,
      totalLikeCount: json['totalLikeCount'] as int,
      rankPosition: json['rankPosition'] as int,
      lastUpdateTime: DateTime.parse(json['lastUpdateTime'] as String),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'userId': userId,
      'totalLikeCount': totalLikeCount,
      'rankPosition': rankPosition,
      'lastUpdateTime': lastUpdateTime.toIso8601String(),
    };
  }

  /// 复制用户排名对象并修改部分属性
  RankingUserEntity copyWith({
    String? userId,
    int? totalLikeCount,
    int? rankPosition,
    DateTime? lastUpdateTime,
  }) {
    return RankingUserEntity(
      userId: userId ?? this.userId,
      totalLikeCount: totalLikeCount ?? this.totalLikeCount,
      rankPosition: rankPosition ?? this.rankPosition,
      lastUpdateTime: lastUpdateTime ?? this.lastUpdateTime,
    );
  }

  @override
  String toString() {
    return 'RankingUserEntity(userId: $userId, rank: $rankPosition, likes: $totalLikeCount)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is RankingUserEntity && other.userId == userId;
  }

  @override
  int get hashCode => userId.hashCode;
}
